package io.rocketman.common.plugin;

import io.rocketman.serialize.Serializer;
import org.junit.Assert;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @author he peng
 * @create 2018/5/28 9:59
 * @see
 */
public class PluginLoaderTest {

    @Test
    public void getPluginLoaderTest() throws Exception {
        PluginLoader pluginLoader = PluginLoader.getPluginLoader(Serializer.class);
        Assert.assertNotNull(pluginLoader);
    }

    @Test
    public void getPluginTest() throws Exception {
        Serializer plugin = (Serializer) PluginLoader.getPluginLoader(Serializer.class).getPlugin("kryo");
        Assert.assertNotNull(plugin);
        Map<String , String> map = new HashMap<>(2);
        map.put("name" , "小猪佩奇");
        map.put("age" , "8");
        byte[] bytes = plugin.serialize(map);
        Assert.assertNotNull(bytes);
        Assert.assertNotEquals(0 , bytes.length);
    }

    @Test
    public void getRuntimePluginTest() throws Exception {
        Serializer plugin = (Serializer) PluginLoader.getPluginLoader(Serializer.class).getRuntimePlugin();
        Assert.assertNotNull(plugin);
        Map<String , String> map = new HashMap<>(2);
        map.put("name" , "小猪佩奇");
        map.put("age" , "8");
        byte[] bytes = plugin.serialize(map);
        Assert.assertNotNull(bytes);
        Assert.assertNotEquals(0 , bytes.length);
    }

    @Test
    public void hasPluginTest() throws Exception {
        boolean hasPlugin = PluginLoader.getPluginLoader(Serializer.class).hasPlugin("sss");
        Assert.assertFalse(hasPlugin);
    }
}
